# Maintainer: Levente Polyak <anthraxx@archlinux.org>
# Contributor: Stéphane Gaudreault <stephane@archlinux.org>
# Contributor: Sylvain HENRY <hsyl20@yahoo.fr>
# Contributor: Hervé YVIQUEL <elldekaa@gmail.com>

_realname=hwloc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.4.0
pkgrel=1
pkgdesc='Portable Hardware Locality is a portable abstraction of hierarchical architectures (mingw-w64)'
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-libtool")
makedepends=("${MINGW_PACKAGE_PREFIX}-cairo"
             "${MINGW_PACKAGE_PREFIX}-libxml2")
optdepends=("${MINGW_PACKAGE_PREFIX}-cairo"
            "${MINGW_PACKAGE_PREFIX}-libxml2")
options=('!docs')
license=('BSD')
url='https://www.open-mpi.org/projects/hwloc/'
source=(https://www.open-mpi.org/software/hwloc/v${pkgver%.*}/downloads/${_realname}-${pkgver}.tar.bz2)
sha256sums=('2b1f1b4adb542911096bdceceb16270e9918908dcd884ab85c2f929c2b3838e9')

prepare() {
  cd ${_realname}-${pkgver}
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --sbindir=${MINGW_PREFIX}/bin \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --enable-static \
    --enable-plugins

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make install DESTDIR="${pkgdir}"
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE

  # Remove unwanted text files
  rm ${pkgdir}${MINGW_PREFIX}/*.txt
}

# vim: ts=2 sw=2 et:
